<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="show">0</div>
    <button id="btn">click</button>
    <script>
      const showEl = document.querySelector("#show");
      const btnEl = document.querySelector("#btn");

      function throttle(fn, duration = 1000) {
        let lastTime = 0;
        return function () {
          let nowTime = new Date().getTime();
          if (nowTime - lastTime > duration) {
            fn.apply(this, arguments);
            lastTime = nowTime;
          }
        };
      }

      btnEl.onclick = throttle(function () {
        showEl.innerHTML = parseInt(showEl.innerHTML) + 1;
      });
    </script>
  </body>
</html>
